<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('积分兑换订单列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label style="width: 105px;">积分兑换方：</label>
                            <select name="convertType" th:with="type=${@dict.getType('points_convert_object')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <label>审批进度：</label>
                            <select name="status" th:with="type=${@dict.getType('points_convert_status')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <label>支付状态：</label>
                            <select name="payStatus" th:with="type=${@dict.getType('point_pay_status')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <!--<li>-->
                        <!--<label>创建时间：</label>-->
                        <!--<input type="text" class="time-input" placeholder="请选择创建时间" name="createTime"/>-->
                        <!--</li>-->
                        <!--<li>-->
                        <!--<label>用户姓名：</label>-->
                        <!--<input type="text" name="trueName"/>-->
                        <!--</li>-->
                        <!--<li>-->
                        <!--<label>用户手机号：</label>-->
                        <!--<input type="text" name="phone"/>-->
                        <!--</li>-->

                        <li class="select-time">
                            <label style="width: 105px;">申请时间：</label>
                            <input type="text" class="time-input" id="startTime" placeholder="开始时间"
                                   name="startTime"/>
                            <span>-</span>
                            <input type="text" class="time-input" id="endTime" placeholder="结束时间"
                                   name="endTime"/>
                        </li>

                        <li>
                            <label style="width: 105px;">关键字查询字段：</label>
                            <select name="fields">
                                <option value="phone" selected>手机号</option>
                                <option value="trueName">姓名</option>
                                <option value="partnerName">申请方名称</option>
                            </select>
                            <input type="text" name="keywords"/>
                        </li>

                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('system:pointsConvert:edit')}]];
    var removeFlag = [[${@permission.hasPermi('system:pointsConvert:remove')}]];

    var passOrNoFlag = [[${@permission.hasPermi('system:pointsConvert:passOrNo')}]];

    var deliverFlag = [[${@permission.hasPermi('system:pointsConvert:deliver')}]];

    var convertTypeDatas = [[${@dict.getType('points_convert_object')}]];
    var statusDatas = [[${@dict.getType('points_convert_status')}]];

    var payStatusDatas = [[${@dict.getType('point_pay_status')}]];


    var prefix = ctx + "system/pointsConvert";

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "积分兑换订单",
            detailView: true,
            onExpandRow: function (index, row, $detail) {
                initChildTable(index, row, $detail);
            },
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: '',
                    visible: false
                },
                {
                    field: 'partnerName',
                    title: '申请方名称'
                },
                {
                    field: 'createTime',
                    title: '申请时间'
                },
                {
                    field: 'convertName',
                    title: '兑换方名称'
                },
                {
                    field: 'convertType',
                    title: '积分兑换类别',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(convertTypeDatas, value);
                    }
                },
                {
                    field: 'realPayAmount',
                    title: '积分总额'
                },
                {
                    field: 'postAmount',
                    title: '邮费'
                },
                {
                    field: 'discountAmount',
                    title: '优惠价格'
                },
                {
                    field: 'payStatus',
                    title: '支付状态',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(payStatusDatas, value);
                    }
                },
                {
                    field: 'payTime',
                    title: '支付时间'
                },
                {
                    field: 'status',
                    title: '审批进度',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(statusDatas, value);
                    }
                },
                {
                    field: 'trueName',
                    title: '姓名'
                },
                {
                    field: 'phone',
                    title: '手机号'
                },
                {
                    field: 'address',
                    title: '地址'
                },
                {
                    field: 'approvalTime',
                    title: '审批时间'
                },
                {
                    field: 'deliveryTime',
                    title: '发货时间'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        // TODO TODO TODO
                        // 判断兑换方是否是平台方
                        if (row.convertType == 0) {
                            // 平台
                            /**
                             * 审批进度
                             0 未审批
                             1 待发货
                             2 已发货
                             3 已拒绝
                             */
                            if (row.status == 0) {
                                // 未审核，进行审核操作
                                actions.push('<a class="btn btn-success btn-xs ' + passOrNoFlag + '" href="javascript:void(0)" onclick="pass(\'' + row.id + '\')"><i class="fa fa-check"></i>审核通过</a> ');

                                actions.push('<a class="btn btn-danger btn-xs ' + passOrNoFlag + '" href="javascript:void(0)" onclick="nopass(\'' + row.id + '\')"><i class="fa fa-remove"></i>拒绝审核</a>');
                            } else if (row.status == 1) {
                                // 等待发货
                                actions.push('<a class="btn btn-success btn-xs ' + deliverFlag + '" href="javascript:void(0)" onclick="deliver(\'' + row.id + '\')"><i class="fa fa-check"></i>确认发货</a> ');
                            }
                        }
                        // actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        // actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });


    // 审核通过
    function pass(id) {
        $.modal.confirm("确认通过审核？", function () {
            var url = prefix + "/pass";
            var data = {"id": id};
            $.operate.submit(url, "post", "json", data);
        });
    }

    function nopass(id) {
        $.modal.confirm("确认拒绝审核？", function () {
            var url = prefix + "/nopass";
            var data = {"id": id};
            $.operate.submit(url, "post", "json", data);
        });
    }


    function deliver(id) {
        $.modal.confirm("确认发货吗？【注意:确认发货后，请到设备列表进行划分设备】", function () {
            var url = prefix + "/deliver";
            var data = {"id": id};
            $.operate.submit(url, "post", "json", data);
        });
    }

    initChildTable = function (index, row, $detail) {
        // 展示详情
        var childTable = $detail.html('<table style="table-layout:fixed"></table>').find('table');
        $(childTable).bootstrapTable({
            url: prefix + "/itemslist",
            method: 'post',
            sidePagination: "server",
            contentType: "application/x-www-form-urlencoded",
            queryParams: {
                pointsConvertId: row.id
            },
            columns: [
                {
                    field: 'id',
                    title: '',
                    visible: false
                },
                {
                    field: 'itemImg',
                    title: '商品图片',
                    formatter: function (value, row, index) {
                        if (value == null || value == "") {
                            return "-";
                        } else {
                            return $.table.imageView(value);
                        }
                    }
                },
                {
                    field: 'itemName',
                    title: '商品名称'
                },
                {
                    field: 'buyCounts',
                    title: '购买数量'
                }
            ]
        });
    };


</script>
</body>
</html>